﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using MyHotel_Common;
using System.Data.SqlClient;

namespace MyHotel_DAO
{
    public class PhieuDichVuDAO : DAO
    {
        protected override object createObjectFromDatarow(System.Data.DataRow row)
        {
            PhieuDichVu phieudv = new PhieuDichVu();
            phieudv.MaMH = int.Parse(row["MaMH"].ToString());
            phieudv.GiaMatHang = int.Parse(row["GiaMatHang"].ToString());
            phieudv.MaPhieu = int.Parse(row["MaPhieu"].ToString());
            phieudv.MaPhieuThue = int.Parse(row["MaPhieuThue"].ToString());
            phieudv.NgaySuDung = DateTime.Parse(row["NgaySuDung"].ToString());
            phieudv.SoLuong = int.Parse(row["SoLuong"].ToString());

            return phieudv;
        }

        public List<PhieuDichVu> getListDichVuByMaPhong(int maPhong)
        {
            string nameProc = "SP_GETDS_DICHVU_BY_MAPHONG";
            DataTable dt = DataProvider.executeStoreProcedureQuery(nameProc, new SqlParameter("@MaPhong", maPhong));

            return getListFromDataTable<PhieuDichVu>(dt); 
        }

        public bool themPhieuDichVu(PhieuDichVu phieuDV)
        {

            string nameProc = "SP_THEM_PhieuDICHVU";
            SqlParameter[] para = new SqlParameter[4];
            para[0] = new SqlParameter("@MaPhieuThue", phieuDV.MaPhieuThue);
            para[1] = new SqlParameter("@MaMH", phieuDV.MaMH);
            para[2] = new SqlParameter("@NgaySuDung", phieuDV.NgaySuDung);
            para[3] = new SqlParameter("@SoLuong", phieuDV.SoLuong);
            
            

            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1);
            
        }

        public bool capNhatPhieuDichVu(PhieuDichVu phieuDV)
        {

            string nameProc = "SP_THEM_PhieuDICHVU";
            SqlParameter[] para = new SqlParameter[4];
            para[0] = new SqlParameter("@MaPhieuThue", phieuDV.MaPhieuThue);
            para[1] = new SqlParameter("@MaMH", phieuDV.MaMH);
            para[2] = new SqlParameter("@NgaySuDung", phieuDV.NgaySuDung);
            para[3] = new SqlParameter("@SoLuong", phieuDV.SoLuong);



            return (DataProvider.executeStoreProcedureNonQuery(nameProc, para) == 1);

        }
    }
}
